package demo1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        //需求：调用Person的sayHello方法
        //1:实例化Person并调用sayHello的方法
        /*
           优点：直接明了
           缺点：代码写死
         */
        Person p = new Person();
        p.sayHello();

        //2:反射调用
        /*
        优点：代码灵活
        缺点：代码多
         */
        Class cls = Class.forName("demo1.Person");
        Person p1 = (Person) cls.newInstance();
        p1.sayHello();

        //3:使用spring容器
        AnnotationConfigApplicationContext context
                = new AnnotationConfigApplicationContext("demo1");
        Person p2 = context.getBean(Person.class);
        p2.sayHello();


    }
}
